﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using NHibernate;

namespace Com.CMS263.DAO
{
   public class StyleImageDAO:BaseService
    {
       public StyleImageDAO() { }
        public int GetMaxId()
        {
            string hql = "from StyleImage order by Id desc";
            try
            {
                StyleImage prod = FindList<StyleImage>(hql, null, 0, 1).First();
                return prod.Id + 1;
            }
            catch (Exception)
            {

                return 1;
            }
        }
        public IList<StyleImage> GetListByPager(int StyleId, int page, int pagesize)
        {
            string hql = " from StyleImage where 1=1 and StyleId=" + StyleId;
            hql += " order by SortId desc";
            return FindList<StyleImage>(hql, null, (page - 1) * pagesize, pagesize);
        }
        public int GetListByPager(int StyleId)
        {
            string hql = " select count(*) from StyleImage where 1=1 and StyleId=" + StyleId;
            return Convert.ToInt32(GetValue(hql));
        }

        public StyleImage GetLastImage(int styleId)
        {
                        
            return FindList<StyleImage>("from StyleImage where StyleId=" + styleId + " order by SortId desc,Id desc ", null, 0, 1).First();
        }

        public IList<StyleImage> GetAllImageByStyleId(int styleId)
        {
           IQuery iq=DBHelper.ExecuteHQL("from StyleImage where StyleId="+styleId+" order by SortId desc ,Id desc ");
           if (iq.List().Count > 0)
           {
               return iq.List<StyleImage>();
           }
           else
           {
               return null;
           }
        }
    }
}
